package com.gpframework.common.weixin.common.message.base;

import com.alibaba.fastjson.JSONObject;
import lombok.ToString;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 微信消息
 *
 * @author zcl
 */
@ToString
public class Template implements Serializable {
    /**
     * 用户openId
     */
    private String touser;
    /**
     * 模版id
     */
    private String template_id;

    private String miniprogram_state;

    private String lang;
    /**
     * 请求地址
     */
    private String url;
    /**
     * 模板字体颜色
     */
    private String topcolor;
    private TemplateItem data;
    private TemplateMiniprogram miniprogram;

    /**
     * 跳转路径
     */
    private String page;

    public static Template New() {
        return new Template();
    }

    private Template() {
        this.data = new TemplateItem();
        this.miniprogram = new TemplateMiniprogram();
    }


    public String getTouser() {
        return touser;
    }

    public Template setTouser(String touser) {
        this.touser = touser;
        return this;
    }

    public String getTemplate_id() {
        return template_id;
    }

    public Template setTemplate_id(String template_id) {
        this.template_id = template_id;
        return this;
    }

    public String getUrl() {
        return url;
    }

    public Template setUrl(String url) {
        this.url = url;
        return this;
    }

    public String getTopcolor() {
        return topcolor;
    }

    public Template setTopcolor(String topcolor) {
        this.topcolor = topcolor;
        return this;
    }

    public TemplateItem getData() {
        return data;
    }

    public Template add(String key, String value, String color) {
        data.put(key, new Item(value, color));
        return this;
    }

    public String getMiniprogram_state() {
        return miniprogram_state;
    }

    public Template setMiniprogram_state(String miniprogram_state) {
        this.miniprogram_state = miniprogram_state;
        return this;
    }

    public String getLang() {
        return lang;
    }

    public Template setLang(String lang) {
        this.lang = lang;
        return this;
    }

    public TemplateMiniprogram getMiniprogram() {
        return miniprogram;
    }

    public void setMiniprogram(TemplateMiniprogram miniprogram) {
        this.miniprogram = miniprogram;
    }

    public void setData(TemplateItem data) {
        this.data = data;
    }

    public Template add(String key, Object value) {
        data.put(key, new Item(value, null));
        return this;
    }

    public Template addMiniprogram(String key, String value) {
        miniprogram.put(key, value);
        return this;
    }

    public String getPage() {
        return page;
    }

    public Template setPage(String page) {
        this.page = page;
        return this;
    }

    /**
     * 直接转化成jsonString
     *
     * @return {String}
     */
    public String build() {
        return JSONObject.toJSONString(this);
    }

    public class TemplateItem extends HashMap<String, Item> {

        private static final long serialVersionUID = -3728490424738325020L;

        public TemplateItem() {
        }

        public TemplateItem(String key, Item item) {
            this.put(key, item);
        }
    }

    public class Item {
        private Object value;
        private String color;

        public Object getValue() {
            return value;
        }

        public void setValue(Object value) {
            this.value = value;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public Item(Object value, String color) {
            this.value = value;
            this.color = color;
        }
    }

    public class TemplateMiniprogram extends HashMap<String, String> {

        private static final long serialVersionUID = -3728490424738325020L;

        public TemplateMiniprogram() {
        }

        public TemplateMiniprogram(String key, String value) {
            this.put(key, value);
        }
    }


}
